from manim import *



class math1(MovingCameraScene):
    def construct(self):
        self.camera.background_color = BLACK  # 设置背景颜色
        self.camera.frame_width = 100  # 设置边框宽度
        self.camera.frame_height = 60  # 设置边框高度
        self.camera.pixel_height = 1080  # 设置像素高度
        self.camera.pixel_width = 1920  # 设置像素宽度
        self.camera.center = ORIGIN  # 设置中心点位置
        self.camera.scale_factor = 1.0  # 设置缩放因子
        #设置横线
        for i in range(6*2+1):       
            dot1=Dot([-50,5*(i-6),0]).set_opacity(0.5)
            dot2=Dot([50,5*(i-6),0]).set_opacity(0.5)
            if i==6:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
                
            else:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
               
            self.add(dot1,dot2,line1)
        #设置竖线
        for i in range(10*2+1):        
            dot3=Dot([(i-10)*5,-30,0]).set_opacity(0.5)
            dot4=Dot([(i-10)*5,30,0]).set_opacity(0.5)
            if i==10:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
                
            else:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
            self.add(dot3,dot4,line2)
        #设置三个点
        dot1 = Dot(radius=1, color=RED)  
        dot1.move_to([-47.5,27.5,0]) 
        dot2 = Dot(radius=1, color=YELLOW)  
        dot2.move_to([-42.5,27.5,0])  
        dot3 = Dot(radius=1, color=GREEN)  
        dot3.move_to([-37.5,27.5,0])
        #镜头跟进效果
        self.camera.frame.save_state()
        #题目出现
        text = Tex(r"\text{设}$f\left( x\right) =\dfrac{1}{2^{x}+1} $\text{,}$x\in R$\text{,则}$f^{\left( 4\right) }\left( 0\right) =$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0)
        
       
        self.play(Write(text),self.camera.frame.animate.scale(0.8))
        self.wait()
        #镜头拉回
        self.play(Restore(self.camera.frame))
        self.play(FadeIn(dot1),run_time=0.1)
        self.play(FadeIn(dot2),run_time=0.1)
        self.play(FadeIn(dot3),run_time=0.1)
         #分析文本
        text100=MarkupText("<b><i>分析/解：</i></b>",color=PINK).scale(5.0).move_to([-35,7.5,0])
        self.play(Create(text100)) 
        self.wait()
        #题目向上移动
        self.play(text.animate().scale(0.8).move_to(UP*20)) 

        #镜头拉近
        self.play(self.camera.frame.animate.scale(0.8).move_to([10,20,0]))

        #箭头引出
        arrow = Arrow(start=[20,25,0],end=[16,23,0], color=RED
                       , stroke_width=20, tip_length=1)
        self.play(Create(arrow))
        #文本
        long_text=("特征识别:\n"
                     "某点处的高阶导")
        text1 = Text(long_text,color=YELLOW,
                   font_size=200).move_to([30,25,0])
        #框框标
        rectangle=Rectangle(color=BLUE,fill_opacity=0.0,width=9,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle.move_to([12, 20, 0])
        self.play(Create(rectangle),Create(text1))
        self.wait()
        #箭头引出
        arrow1 = Arrow(start=[5,15,0],end=[-15,10,0], color=RED
                       , stroke_width=20, tip_length=1)
        #箭头引出
        arrow2 = Arrow(start=[8,15,0],end=[0,10,0], color=RED
                       , stroke_width=20, tip_length=1)
        #箭头引出
        arrow3 = Arrow(start=[11,15,0],end=[15,10,0], color=RED
                       , stroke_width=20, tip_length=1)
        #箭头引出
        arrow4 = Arrow(start=[14,15,0],end=[30,10,0], color=RED
                       , stroke_width=20, tip_length=1)
        self.play(Create(arrow1),Create(arrow2),Create(arrow3),Create(arrow4))
        #文本
        text2 = Tex(r"\text{奇偶性}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-15,5,0])
         #文本
        text3 = Tex(r"\text{泰勒展开}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,5,0])
         #文本
        text4 = Tex(r"\text{莱布尼兹}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([15,5,0]) 
         #文本
        text5 = Tex(r"\text{构造递推}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([30,5,0])
        
        self.play(Create(text2),Create(text3),Create(text4),Create(text5))
        #镜头拉回
        self.play(Restore(self.camera.frame))
        ##框框移动
        rectangle1=Rectangle(color=GREEN,fill_opacity=0.0,width=10,height=5
                            ,stroke_color=GREEN,stroke_width=20)
        rectangle1.move_to([-15,5,0])
        self.play(Create(rectangle1))
        self.wait()
        self.play(rectangle1.animate().shift(15*RIGHT))
        self.wait()
        self.play(rectangle1.animate().shift(15*RIGHT))
        self.wait()
        self.play(rectangle1.animate().shift(15*RIGHT))
        self.wait()
        self.play(rectangle1.animate().shift(45*LEFT))

        text6 = Tex(r"\text{奇函数定义:}$f\left( -x\right) +f\left( x\right) =0$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-15,0,0])
        self.play(Create(text6))
        text7 = Tex(r"\text{题给函数:}$f\left( -x\right) +f\left( x\right) =\dfrac{1}{2^{-x}+1}+\dfrac{1}{2^{x}+1}=1$"
                    ,color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-5,-5,0])
        self.play(Create(text7))
        text8 = Tex(r"\text{令:}$g\left( x\right) =f\left( x\right) -\dfrac{1}{2}$"
                    ,color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-15,-10,0])
        self.play(Create(text8))
        text9 = Tex(r"\text{（奇函数）}"
                    ,color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text8,RIGHT,buff=1)
        self.play(Create(text9))

        #箭头引出
        arrow5 = Arrow(start=[10,-10,0],end=[15,-10,0], color=RED
                       , stroke_width=20, tip_length=1)
        
        self.play(Create(arrow5))

        text10 = Tex(r"$g^{(2n)}\left( x\right) $"
                    ,color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([20,-10,0])
        self.play(Create(text10))
        text11 = Tex(r"\text{（奇函数）}"
                    ,color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text10,RIGHT,buff=1)
        self.play(Create(text11))


        text12 = Tex(r"$f^{(4)}\left( x\right) =g^{(4)}\left( x\right) =0$"
                    ,color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text8,DOWN,buff=1)
        self.play(Create(text12))
















        self.wait()
       
